home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
dte5_1.zip
/
HWIND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-06
|
20KB
|
646 lines
/*
* Written by Douglas Thomson (1989/1990)
*
* This source code is released into the public domain.
*/
/*
* Name: hardware independent screen IO module
* Purpose: This file contains the code to interface the rest of the
* editor to the display and input hardware.
* File: hwind.c
* Author: Douglas Thomson
* System: this file is intended to be system-independent
* Date: October 2, 1989
* Notes: This is the only module that is allowed to call the hardware
* dependent display IO library.
* Typically, functions here check whether any action is
* necessary (for example, the cursor may already happen to be
* in the required position), call hardware dependent functions
* to achieve the required effect, and finally update status
* information about the current state of the terminal display.
* The idea behind this approach is to keep the hardware
* dependent code as small and simple as possible, thus making
* porting the code easier.
*/
#ifdef HPXL
#include "commonh"
#include "hwdeph"
#else
#include "common.h"
#include "hwdep.h"
#endif
#include <string.h>
/*
* prototypes for all functions in this file
*/
void xygoto ARGS((int col, int line));
void set_attr ARGS((char attr));
int c_insert ARGS((void));
int c_delete ARGS((void));
int eol_clear ARGS((void));
int c_avail ARGS((void));
int c_input ARGS((void));
void c_uninput ARGS((char c));
void c_output ARGS((int c));
void s_output ARGS((char *s));
void force_blank ARGS((void));
void initialize ARGS((void));
void terminate ARGS((void));
void line_del ARGS((int line));
void line_ins ARGS((int ins_line));
void window_scroll_up ARGS((int top, int bottom));
void window_scroll_down ARGS((int top, int bottom));
/*
* Name: xygoto
* Purpose: To move the cursor to the required column and line.
* Date: October 2, 1989
* Passed: col: desired column (0 up to max)
* line: desired line (0 up to max)
* Notes: This function makes some attempt to use shorter movement
* commands for simple movements (initially, only backspace
* to move left one space).
*/
void xygoto(col, line)
int col;
int line;
{
int diff; /* how far backwards the cursor must be moved */
/*
* If the cursor is on the right line, then a simpler movement
* may be possible.
*/
if (g_display.line == line) {
if ((diff = g_display.col - col) == 0) {
/*
* the cursor was in exactly the right spot, so no
* action required.
*/
return;
}
else if (diff == 1) {
/*
* the cursor only needs to move one space left, so try
* simply backspacing (if the hardware supports it)
*/
if (hw_backspace()) {
g_display.col = col;
return;
}
}
}
/*
* use a full cursor addressing command. The hardware is required
* to provide such a command, so there is no need to check.
*/
g_display.col = col;
g_display.line = line;
hw_xygoto();
}
/*
* Name: set_attr
* Purpose: To record the attribute to be used for the next character
* output.
* Date: October 2, 1989
* Passed: attr: desired new attribute
* Returns: [g_status.wanted]: attribute to use next
* Notes: Since other hardware commands can need to fiddle with the
* attribute, it is better not to bother actually outputting
* the hardware attribute command. This is done immediately
* prior to sending the actual character.
*/
void set_attr(attr)
char attr;
{
g_status.wanted = attr;
}
/*
* Name: c_insert
* Purpose: To insert space for one character at the cursor position.
* Date: October 2, 1989
* Notes: If this function is available in the hardware, then it must
* leave the cursor in its original position (or else
* explicitly undefined [line = col = -1]) and insert one
* character in front of the character that used to be under
* the cursor.
* No assumption is made about what the attribute of the inserted
* character will be!
*/
int c_insert()
{
int col; /* used to copy characters along */
int old_col; /* to remember current column */
int old_line; /* to remember current line */
/*
* It is permissible for hardware functions to leave the current
* cursor position undefined (-1, -1). Hence we need to store the
* current location for use later.
*/
old_col = g_display.col;
old_line = g_display.line;
if (hw_c_insert()) {
/*
* update memory version of screen
*/
for (col=g_display.ncols-1; col > old_col; col--) {
g_screen[old_line][col] =
g_screen[old_line][col-1];
}
g_screen[old_line][old_col].c = ' ';
g_screen[old_line][old_col].attr = 0xFF;
return TRUE;
}
return FALSE;
}
/*
* Name: c_delete
* Purpose: To delete the character under the cursor.
* Date: October 10, 1989
* Notes: If this function is available in the hardware, then it must
* leave the cursor in its original position (or else
* explicitly undefined [line = col = -1]) and delete the
* character under the cursor.
* The character which appears at the end of the line after the
* delete is assumed to be a space with the normal attribute.
*/
int c_delete()
{
int col; /* used to copy characters along */
int old_col; /* to remember current column */
int old_line; /* to remember current line */
/*
* It is permissible for hardware functions to leave the current
* cursor position undefined (-1, -1). Hence we need to store the
* current location for use later.
*/
old_col = g_display.col;
old_line = g_display.line;
if (hw_c_delete()) {
/*
* update memory version of screen
*/
for (col=old_col; col < g_display.ncols-1; col++) {
g_screen[old_line][col] =
g_screen[old_line][col+1];
}
g_screen[old_line][g_display.ncols-1].c = ' ';
g_screen[old_line][g_display.ncols-1].attr = g_display.normal;
return TRUE;
}
return FALSE;
}
/*
* Name: eol_clear
* Purpose: To clear the current line from the cursor to the end of the
* line to normal spaces.
* Date: October 2, 1989
* Notes: If this function is available in the hardware, then it must
* clear all the rest of the line to spaces, all with the normal
* attribute, and leave the cursor exactly where it was (or else
* explicitly undefined [line = col = -1]).
*/
int eol_clear()
{
int col;
int old_col; /* to remember current column */
int old_line; /* to remember current line */
old_col = g_display.col;
old_line = g_display.line;
if (!hw_clreol()) {
return FALSE;
}
for (col=old_col; col < g_display.ncols; col++) {
g_screen[old_line][col].c = ' ';
g_screen[old_line][col].attr = g_display.normal;
}
return TRUE;
}
/*
* Name: c_avail
* Purpose: To test whether or not there is a character available to be
* read from the user.
* Date: October 2, 1989
* Notes: Under some circumstances it is convenient to be able to push
* a few characters back into the input stream, making it appear
* to the rest of the editor that the user typed something
* different (for example, the tab key might be turning into
* the required number of spaces).
*/
int c_avail()
{
if (g_status.ungotcount) {
return TRUE;
}
return hw_c_av